<template>
	<view>
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="Hello Pro"></u-loading-page>
		<view v-if="!loadding" class="main">
			<view class="top">
				<view class="title">
					<u-icon color="#ff9900" size="18" name="account"></u-icon>
					<text>{{name}}</text>
				</view>
				<u-line></u-line>
				<view class="sn">
					<u-icon color="#ff9900" size="18" name="tags"></u-icon>
					<text>SN：{{sn}}</text>
				</view>
				<u-line></u-line>
				<view class="sn">
					<u-icon color="#ff9900" size="18" name="integral"></u-icon>
					<text>默认费率：{{dRate}}</text>
				</view>
				<u-line></u-line>
				<view class="name">
					<u-icon color="#ff9900" size="18" name="clock"></u-icon>
					<text>绑定时间：{{st}}</text>
				</view>
			</view>
			<view class="inputs">
				<view class="lefts">
					费率调整
				</view>
				<u-number-box v-model="rates" :min="min" :max="max" step="0.01" decimal-length="2" disabledInput color="#ffffff" bgColor="#2979ff" iconStyle="color: #fff"></u-number-box>
			</view>
			<view class="saveBtn" @click="saveBtn">
				保 存
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadding: false,
				isFalse: true,
				types: 1,
				data: [],
				userinfo: {},
				product_id: '',
				sn: '',
				name: '',
				dats: {},
				rates: '0.60',
				dRate: '',
				min: '',
				max: '',
				st: '',
				product_id: '',
				typs: 'D',
			}
		},
		onLoad(e) {
			this.product_id = e.pid
			this.sn = e.sn
			this.name = e.name
			this.types = e.type
			this.st = e.st
			this.rates = e.rate*100/100
			this.dRate = e.rate
			this.userinfo = uni.getStorageSync('userinfo')
			if (e.type == 2) {
				this.typs = 'T'
			}
			this.getFeeTemps()
		},
		methods: {
			// 保存费率修改
			saveBtn() {
				var that = this
				if (this.rates*100 >= this.min*100 && this.rates*100 <= this.max*100) {
					uni.showModal({
						title: '提示',
						content: '确定要调整费率吗？',
						success: function(res) {
							if (res.confirm) {
								that.rateSaveFun()
							}
						}
					});
				} else {
					uni.showToast({
						title: '需要调整的费率错误',
						icon: "none"
					});
					return false
				}
			},
			// 获取费率模版
			async getFeeTemps() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Prouduct/fee_temps',
					data: {
						typs: this.typs,
						proid: this.product_id,
						sn: this.sn
					},
					header: {
						'token': this.userinfo.token
					}
				});
				if (res.code == 1) {
					this.min = res.data.mini
					this.max = res.data.maxi
					this.rates = res.data.maxi
				}
			},
			// 提交费率修改
			async rateSaveFun() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Prouduct/fee_mods_loading',
					data: {
						proid: this.product_id,
						typs: this.typs,
						sn: this.sn,
						appyRate: this.rates,
						origRate: this.dRate
					},
					header: {
						'token': this.userinfo.token
					}
				});
				uni.showToast({
					title: res.msg,
					icon: "none"
				});
				if (res.code == 1) {
					setTimeout(function() {
						uni.navigateBack({
							delta: 1
						});
					}, 1500);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f3f4f6;
	}

	.main {
		.top {
			margin-bottom: 20rpx;
			background-color: #ffffff;
			padding: 30rpx 20rpx;
			font-size: 28rpx;

			.title {
				font-size: 32rpx;
				font-weight: bold;
				padding-bottom: 20rpx;
				display: flex;
				justify-content: flex-start;

				text {
					padding-left: 10rpx;
				}
			}

			.sn {
				font-weight: bold;
				padding: 20rpx 0;
				display: flex;
				justify-content: flex-start;

				text {
					padding-left: 10rpx;
				}
			}

			.name {
				color: #909399;
				padding-top: 20rpx;
				display: flex;
				justify-content: flex-start;

				text {
					padding-left: 10rpx;
				}
			}

			.bottom-line {
				border-bottom: 1px dashed #f4f4f5;
			}
		}

		.inputs {
			padding: 20rpx;
			background-color: #ffffff;
			display: flex;
			justify-content: space-between;
			.lefts {
				padding-top: 8rpx;
			}
		}

		.saveBtn {
			margin: 30rpx 20rpx 30rpx 20rpx;
			text-align: center;
			background-color: #2979ff;
			border-radius: 10rpx;
			padding: 30rpx 0;
			color: #ffffff;
			font-size: 32rpx;
		}
	}
</style>